//
//  ViewController.swift
//  ZSLimitTextField
//
//  Created by safiriGitHub on 08/10/2020.
//  Copyright (c) 2020 safiriGitHub. All rights reserved.
//

import UIKit
import ZSLimitTextField

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        numberTF.inputLimitType = .RegularOnlyNumber(5)
        numberTF2.inputLimitType = .RegularDecimalNumber(4, 2)
        numberTF3.inputLimitType = .RegularOnlyNumberExceptLeadingZero(3)
        numberTF4.inputLimitType = .RegularTelephoneNumber
        numberTF5.inputLimitType = .RegularDecimalNumberExceptLeadingZero(3, 3)
        numberTF6.inputLimitType = .RegularIDCardNumber
        numberTF7.inputLimitType = .RegularMaxCharacter(6)
        numberTF7.operationUppercasedLimit = true
        numberTF8.inputLimitType = .RegularNone
        numberTF8.operationLengthLimit = 5
        numberTF8.operationUppercasedLimit = false
        numberTF8.completeTextClosure = { (text) in
            print(text)
        }
        numberTF8.operationCustomClosure = { (old, new) in
            print("old-\(old),new-\(new)")
            return "乌拉拉"
        }
        
        numberTF9.inputLimitType = .RegularChinese(8)
        numberTF10.inputLimitType = .RegularNumbersLetters(6)
        
        tf11.inputLimitType = .RegularExpress("[\\u4E00-\\u9FA5\\(\\)（）]*")
        
        tf12.inputLimitType = .RegularPasswordStyle1(10)
        tf12.isSecureTextEntry = true
        tf12.operationPasswordDeleteOne = true
        
        tf13.inputLimitType = .RegularNoSpace
        tf14.inputLimitType = .RegularChineseNumbersLetters(10)
        
        //tf15.inputLimitType = .RegularExpress("^[\\u4E00-\\u9FA5\\(\\)（）]{0, 5}$")
        //Can't do regex matching, reason: Can't open pattern U_REGEX_BAD_INTERVAL (string 套, pattern ^[\u4E00-\u9FA5\(\)（）]{0, 5}$, case 0, canon 0)
        //"{}"中有空格时会使程序崩溃
        tf15.inputLimitType = .RegularExpress("^[\\u4E00-\\u9FA5\\(\\)（）]{0,5}$")
        
        tf16.inputLimitType = .RegularOnlyNumber(10)
        tf16.operationIsComplyInputLimitType = false
        tf16.operationLengthLimit = 10
        tf16.operationCustomClosure = { (_, new) in
            print(new)
            let d = new+"fwf"
            print(d)
            return d
        }
        
        
        tf17.delegate = tfdelegate
        tf17.textAlignment = .right
        tf17.keyboardType = .numberPad

//        tfdelegate.operationIsComplyInputLimitType = false
        tfdelegate.operationCustomClosure = { (old, new) in
            if old.count > 11 { return old }
            let result = new+" "
            return result
        }
    }
    let tfdelegate = LimitTextFieldDelegate()
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    @IBOutlet weak var numberTF: LimitTextField!
    @IBOutlet weak var numberTF2: LimitTextField!
    @IBOutlet weak var numberTF3: LimitTextField!
    @IBOutlet weak var numberTF4: LimitTextField!
    @IBOutlet weak var numberTF5: LimitTextField!
    @IBOutlet weak var numberTF6: LimitTextField!
    @IBOutlet weak var numberTF7: LimitTextField!
    @IBOutlet weak var numberTF8: LimitTextField!
    @IBOutlet weak var numberTF9: LimitTextField!
    @IBOutlet weak var numberTF10: LimitTextField!
    
    @IBOutlet weak var tf11: InputLimitTextField!
    @IBOutlet weak var tf12: LimitTextField!
    @IBOutlet weak var tf13: LimitTextField!
    @IBOutlet weak var tf14: LimitTextField!
    @IBOutlet weak var tf15: LimitTextField!
    @IBOutlet weak var tf16: LimitTextField!
    @IBOutlet weak var tf17: LimitTextField!
}

